package com.hadoop.nline;

import com.hadoop.kv.KVTextMapper;
import com.hadoop.kv.KVTextReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.KeyValueLineRecordReader;
import org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat;
import org.apache.hadoop.mapreduce.lib.input.NLineInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * Created by yu756 on 2020/1/18 17:33
 */
public class NlineDriver {


    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {


        args = new String[]{
                "e:/input/inputNline", "e:/output/outputNline"
        };

        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
        job.setJarByClass(NlineDriver.class);

        job.setMapperClass(NlineMapper.class);
        job.setReducerClass(NlineReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        // 设置多少行一个切片
        NLineInputFormat.setNumLinesPerSplit(job, 3);
        //切片规则
        job.setInputFormatClass(NLineInputFormat.class);

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));


        boolean result = job.waitForCompletion(true);

        System.exit(result ? 0 : 1);


    }


}
